﻿using System.Web.Mvc;
using System.Web.Routing;
using System.Web.Security;

namespace MVCLD
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            #region Routes to Ignore
                routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 
            #endregion

            #region Category Routes
                routes.MapRoute(
                "payment",
                "article/payment",
                    new { controller = "article", action = "payment" }
                );

                routes.MapRoute(
                        "article-submit",
                        "article/submit/{id}",
                       new { controller = "article", action = "submit", id = "" }
                );

                routes.MapRoute(
                            "category-browse",
                            "cat/{urlid}/{catname}/{p}",
                            new { controller = "category", action = "index", urlid = "", catname = "", p = "" }
                );
            #endregion

            #region Article Routes
                routes.MapRoute(
                            "article-view",
                            "article/{urlid}/{articlename}",
                            new { controller = "article", action = "details", urlid = "", articlename = ""}
                );
            #endregion

            #region Default
                routes.MapRoute(
                    "Default",
                    "{controller}/{action}/{id}",
                    new { controller = "home", action = "index", id = UrlParameter.Optional }
                );
            #endregion

        }

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            RegisterRoutes(RouteTable.Routes);
        }

        protected void Application_AuthenticateRequest()
        {
            if (User != null)
                Membership.GetUser(true);
        }
    }
}